#ifndef ALIGN_H
#define ALIGN_H

#include <QWidget>
#include <QTimer>

namespace Hydra_Align {

typedef enum _align_state
{
    INIT,
    ALIGN,
    NOTALIGN,
    FALLBACK
}ALIGN_STATE;

}

using namespace Hydra_Align;

class Align : public QWidget
{
    Q_OBJECT

public:
    Align(QWidget *parent = 0);
    void setInterval(quint16 interval);
    void setStatus(ALIGN_STATE state);


public slots:
    void refresh();

protected:
    void paintEvent(QPaintEvent *event);
    void resizeEvent(QResizeEvent *event);
    void initParam();
    void drawTrainBody(QPainter *pPainter);                             // 绘制车身
    void drawWheel(QPainter *pPainter);                                 // 绘制车轮
    void drawAlignTag(QPainter *pPainter);                              // 绘制对准信标




private:
    QTimer mTimer;
    QPoint mCenter;                                                     // 控件中心点
    quint8 mTrainHeightProportion = 50;                                 // 列车图标高度占控件高度的百分比
    quint8 mTrainBodyHeightProportion = 80;                             // 列车图标车身高度占列车高度的百分比
    float mTrainHeight = 0;                                             // 列车图标高度
    quint8 mTrainTopLengthProportion = 175;                             // 列车图标上边界长度与图标高度的比例
    quint8 mTrainBottomLengthProportion = 240;                          // 列车图标下边界长度与图标高度的比例
    quint8 mWheelDiameterProportion = 35;                               // 图标车轮直径占车身高度的百分比
    quint8 mAxleDistProportion = 60;                                    // 2个车轮圆心距离占车身下边界长度的百分比
    QColor mAlignColor = QColor(45, 144, 51);                           // 对准状态颜色
    QColor mNotAlignColor = QColor(189, 0, 0);                          // 未对准状态颜色
    QColor mFallBackColor = QColor(255, 242, 0);                        // 推行状态颜色
    quint16 mTopLength;                                                 // 上边界长度
    quint16 mBottomLength;                                              // 下边界长度
    ALIGN_STATE mState = ALIGN_STATE::INIT;
    QRect mAlignTagRect;                                                // 对准信标矩形
    quint8 mAlignTagDistProportion = 180;                               // 对准信标中心距离车轮圆心的距离与车轮半径比例
    QPoint mTopLeft;
    QPoint mTopRight;
    QPoint mBottomLeft;
    QPoint mBottomRight;
    QRect mWheelRect1;
    QRect mWheelRect2;
};


#endif // ALIGN_H
